home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / AUDIO.ZIP / FLANGE.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-12-11  |  8.8 KB  |  262 lines

  1. *
  2. *
  3. *   FLANGE.ASM - flanging effect for TI DSK module.
  4. *
  5. *
  6.  
  7. *
  8. *   Knobs - adjust these values within suggested range for
  9. *           variations on the effect.
  10. *
  11. *   Patch Name          Dry     Wet     FB     Step    Range     Delay
  12. * Very slow flange     07fffh  07fffh  00000h  0008h    060h     0000h
  13. *   Flange w/ FB       07fffh  07fffh  06800h  0020h    050h     0000h
  14. *  Invert flange       07fffh  08000h  00000h  000eh    060h     0000h
  15. * Invert w/ invert FB  07fffh  08000h  0a000h  0012h    060h     0000h
  16. *    Fast flange       07fffh  07fffh  01000h  0180h    038h     0008h
  17. *     Chorus           07fffh  07fffh  0000h   0040h    070h     0350h
  18. *
  19. DRY_LEVEL       .set    07fffh  ; (0 - 07fffh dry signal level)
  20. WET_LEVEL       .set    07fffh  ; (08000h - 07fffh wet signal level)
  21. FB_LEVEL        .set    01000h  ; (08000h - 07fffh regeneration amount)
  22. SWEEP_STEP      .set    00080h  ; (01h - 07fffh sweep rate)
  23. SWEEP_RANGE     .set    00050h  ; (010h - 03e0h sweep width)
  24. SWEEP_DELAY     .set    00000h  ; (0 - 3e0h delay)
  25.  
  26. *
  27. *   Misc. defines
  28. *
  29. BUF             .set    0410h   ; main circular buffer start and end
  30. BUFEND          .set    0800h
  31. SWEEPUP         .set    0       ; flag value for AR5
  32. SWEEPDOWN       .set    1       ; ditto
  33.  
  34. *
  35. *   Data storage
  36. *
  37. SWEEPCNT        .set    00h ; primary interp factor
  38. SWEEPCOMP       .set    01h ; complement of interp factor
  39. STEP            .set    02h ; inc/dec value for sweepcnt
  40. TMP             .set    03h ; temporary storage reg
  41. INPVAL          .set    04h ; input value
  42. OUTVAL          .set    05h ; output value
  43. FEEDBACK        .set    06h ; mix params...
  44. WET             .set    07h
  45. DRY             .set    08h
  46.  
  47.         .include "setup.asm"
  48.         
  49. *
  50. *                               main
  51. *
  52. main:
  53.         ssxm                    ; set sign extension mode
  54.         spm     1               ; set P shift for Q15 (1 bit left shift
  55.                                 ; from P => accum)
  56.         ldpk    8               ; data at 0400h
  57.         
  58.         lrlk    AR0,BUFEND      ; permanently point to end of mem buf
  59.         lrlk    AR1,BUF         ; write ptr, point to start of mem buf
  60.         lrlk    AR4,SWEEP_RANGE ; breadth of sweep
  61.         sar     AR4,TMP
  62.         lalk    SWEEP_DELAY     ; add in delay factor for chorus effects
  63.         add     TMP
  64.         sacl    TMP
  65.         lalk    BUFEND          ; calc starting point for read ptrs
  66.         sub     TMP             ; end of buf minus sweep range
  67.         subk    1               ; keep 'em from getting too close to write ptr
  68.         sacl    TMP
  69.         lar     AR2,TMP         ; load 1st read ptr
  70.         lar     AR3,TMP         ; 2nd read ptr, initial value for first access
  71.         lrlk    AR5,SWEEPUP     ; set initial sweep direction
  72.         lack    0
  73.         sacl    SWEEPCNT        ; set initial fractional sweep
  74.         lalk    SWEEP_STEP      ; install sweep rate
  75.         sacl    STEP
  76.         lalk    FB_LEVEL
  77.         sacl    FEEDBACK        ; delayed signal feedback mix
  78.         lalk    WET_LEVEL
  79.         sacl    WET             ; delayed signal output mix
  80.         lalk    DRY_LEVEL
  81.         sacl    DRY             ; straight signal output mix
  82.                         
  83.         lack    014h            ; enable AIC recv interrupts
  84.         ldpk    0
  85.         sacl    IMR
  86.         
  87.         ; loop here forever processing interrupts
  88. loop:   idle
  89.         b       loop
  90.  
  91. *
  92. *                               rint
  93. *
  94. *   Recv interrupt handler performs all the work. Since there is
  95. *   no main thread, there is no need to save or restore regs.
  96. *   We can assume:
  97. *
  98. *   AR0 - points to end of buffer
  99. *   AR1 - current write ptr
  100. *   AR2 - 1st read ptr
  101. *   AR3 - 2nd read ptr
  102. *   AR4 - sweep range counter
  103. *   AR5 - sweep direction flag
  104. *
  105. rint:
  106.         ; note: no need to save/restore processor state since
  107.         ; main thread does absolutely nothing
  108.  
  109.         sovm                    ; set clipping overflow mode for the
  110.                                 ; "analog" processing
  111.         ldpk    0                                       
  112.         lac     DRR             ; read in new input value
  113.         ldpk    8
  114.         sfr                     ; dump low 2 junk bits
  115.         sfr
  116.         sacl    INPVAL          ; temporary storage
  117.         
  118.         ; interpolate ouput value from the two read ptrs
  119.         lalk    32767           ; develop complement of fractional
  120.         sub     SWEEPCNT        ; sweep position
  121.         sacl    SWEEPCOMP
  122.         larp    AR2             ; use 1st read ptr
  123.         lt      SWEEPCNT        ; get fractional sweep position
  124.         mpy     *,AR3           ; scale 1st read value
  125.         ltp     SWEEPCOMP
  126.         mpy     *,AR1           ; scale 2nd read value
  127.         apac                    ; glob 'em together
  128.         sach    OUTVAL          ; this will be our "wet" output value
  129.         
  130.         ; do feedback
  131.         lt      OUTVAL
  132.         mpy     FEEDBACK        ; scale feedback to taste
  133.         pac
  134.         addh    INPVAL
  135.         sach    *+              ; store finished input value thru AR1
  136.         cmpr    0               ; check for wrap on store ptr
  137.         bbz     nowrap1,*,AR5   ; (arp to directon flag)
  138.         lrlk    AR1,BUF
  139. nowrap1:
  140.  
  141.         ; do level scaling on direct and wet
  142.         lt      OUTVAL
  143.         mpy     WET             ; scale wet signal
  144.         pac
  145.         lt      INPVAL          ; get original input value
  146.         mpy     DRY             ; scale dry signal
  147.         apac                    ; generate composite final output
  148.         sach    OUTVAL
  149.         lac     OUTVAL          ; prepare final output for AIC
  150.         andk    0fffch          ; clear lowest 2 bits
  151.  
  152.         ldpk    0       
  153.         sacl    DXR             ; do output
  154.         ldpk    8
  155.         
  156.         ;
  157.         ; now update our sweep stuff, 1st see which direction we're going
  158.         ;
  159.         rovm                    ; normal overflow operation for arithmetic
  160.         banz    down,*,AR2
  161.         
  162.         ;
  163.         ; UPWARD SWEEP (delay decreasing sweep)     
  164.         ;
  165.         ; always move forward at least one notch
  166.         sar     AR2,TMP         ; copy AR2 to AR3
  167.         lar     AR3,TMP
  168.         mar     *+              ; inc AR2
  169.         cmpr    0
  170.         bbz     nowrap2,*,AR3
  171.         lrlk    AR2,BUF
  172. nowrap2:
  173.         ; now update fractional delay
  174.         zac                     ; clear accum
  175.         addh    SWEEPCNT        ; use high accum for calc
  176.         addh    STEP
  177.         sach    SWEEPCNT
  178.         bnv     done,*,AR2      ; fractional part didn't overflow,
  179.                                 ; no need to advance sweep further
  180.                                     
  181.         ; fractional portion overflowed, adjust main sweep forward
  182.         sar     AR2,TMP         ; move AR2 to AR3
  183.         lar     AR3,TMP
  184.         mar     *+              ; inc AR2
  185.         cmpr    0
  186.         bbz     nowrap3,*,AR4   ; (arp to sweep cnt AR4)
  187.         lrlk    AR2,BUF
  188. nowrap3:
  189.         lac     SWEEPCNT
  190.         andk    07fffh          ; mask sign bit
  191.         sacl    SWEEPCNT
  192.  
  193.         ; adjust main sweep counter
  194.         mar     *-
  195.         banz    done
  196.         
  197.         ; main sweep expired, reload, swap step sign
  198.         lrlk    AR4,SWEEP_RANGE
  199.         lac     STEP            ; invert sign of step value
  200.         neg
  201.         sacl    STEP
  202.         lark    AR5,SWEEPDOWN   ; show new direction
  203.         b       done
  204.         
  205.         ; DOWNWARD SWEEP (delay increasing)
  206. down:
  207.         lac     SWEEPCNT
  208.         add     STEP            ; step is negative here so we're actually
  209.         sacl    SWEEPCNT        ; subtracting
  210.         blz     underflow,*,AR2 ; cnt went less than zero, skip ptr advance
  211.         
  212.         ; no underflow, advance ptrs but skip rest of sweep updates
  213.         sar     AR2,TMP         ; copy AR3 to AR2
  214.         lar     AR3,TMP
  215.         mar     *+              ; inc AR2
  216.         cmpr    0
  217.         bbz     done
  218.         lrlk    AR2,BUF
  219.         b       done
  220.         
  221.         ; fractional portion underflowed, update major sweep
  222. underflow:
  223.         lac     SWEEPCNT        ; mask off sign stuff from underflow
  224.         andk    07fffh
  225.         sacl    SWEEPCNT
  226.         larp    AR4
  227.         mar     *-
  228.         banz    done
  229.         
  230.         ; main sweep expired, reload, swap step sign
  231.         lrlk    AR4,SWEEP_RANGE
  232.         lac     STEP            ; invert sign of step value
  233.         neg
  234.         sacl    STEP
  235.         lark    AR5,SWEEPUP     ; show new direction
  236.         
  237.         ;
  238.         ; DONE
  239.         ;
  240. done:
  241.         eint
  242.         ret
  243.          
  244.  
  245. *
  246. *                               tint
  247. *
  248. *   Timer interrupt - not used.
  249. *
  250. tint:
  251.         eint
  252.         ret
  253.  
  254. *
  255. *                               xint
  256. *
  257. *   AIC xmit interrupt - not used.
  258. *       
  259. xint:
  260.         eint
  261.         ret
  262.